// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   Dict_control.java

package sql;

import bo.Dict;
import control.database.DataBase;
import java.io.PrintStream;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Dict_control
{

    public Dict_control()
    {
    }

    public String insert(Dict dict)
        throws SQLException
    {
        String message = "insert failse";
        ResultSet rs = null;
        DataBase db = new DataBase();
        String sql = "insert into dict(tablename,fieldname,value,content)values('" + dict.getTablename() + "','" + dict.getFieldname() + "','" + dict.getValue() + "','" + dict.getContent() + "')";
        db.executeUpdate(sql);
        System.out.println(sql);
        db.closeStmt();
        db.closeConn();
        sql = "select * from dict where tablename='" + dict.getTablename() + "'";
        for(rs = db.executeQuery(sql); rs.next();)
            message = "insert successfull";

        rs.close();
        db.closeStmt();
        db.closeConn();
        return message;
    }

    public Dict select(String tablename)
        throws SQLException
    {
        ResultSet rs = null;
        Dict dict = new Dict();
        DataBase db = new DataBase();
        String sql = "select * from dict where tablename='" + tablename + "'";
        System.out.println("username" + sql);
        rs = db.executeQuery(sql);
        if(rs.next())
        {
            dict.setTablename(tablename);
            dict.setFieldname(rs.getString("fieldname"));
            dict.setContent(rs.getString("content"));
            dict.setValue(rs.getString("value"));
        }
        rs.close();
        db.closeStmt();
        db.closeConn();
        return dict;
    }

    public String delete(String tablename)
        throws SQLException
    {
        String message = "";
        ResultSet rs = null;
        Dict dict = new Dict();
        DataBase db = new DataBase();
        String sql = "delete from dict where tablename='" + tablename + "'";
        System.out.println("delete dict" + sql);
        db.executeUpdate(sql);
        db.closeStmt();
        db.closeConn();
        sql = "select * from dict where tablename='" + tablename + "'";
        rs = db.executeQuery(sql);
        if(rs.next())
            message = "delete failse";
        else
            message = "delete successfull";
        rs.close();
        db.closeStmt();
        db.closeConn();
        return message;
    }

    public String update(Dict dict)
        throws SQLException
    {
        String message = "";
        ResultSet rs = null;
        DataBase db = new DataBase();
        String sql = "update dict set tablename='" + dict.getTablename() + "',fieldname='" + dict.getFieldname() + "',value='" + dict.getValue() + "',content='" + dict.getContent() + "'where tablename='" + dict.getTablename() + "'";
        System.out.println("update dict" + sql);
        db.executeUpdate(sql);
        db.closeStmt();
        db.closeConn();
        sql = "select * from dict where tablename='" + dict.getTablename() + "'";
        System.out.println("select dict" + sql);
        rs = db.executeQuery(sql);
        for(message = "insert failse"; rs.next(); message = "insert successfull");
        rs.close();
        db.closeStmt();
        db.closeConn();
        return message;
    }

    public static void main(String args[])
        throws SQLException
    {
        Dict dict = new Dict();
        Dict_control dc = new Dict_control();
        dict.setTablename("tablename");
        dict.setFieldname("fieldname");
        dict.setValue("value");
        dict.setContent("content");
        String s = dc.insert(dict);
        System.out.println(s);
    }
}
